/**
 * Copyright &copy; 2018-2018 <a href="#">聚成科技</a> All rights reserved.
 */
package com.jckj.core.util;

import com.jckj.core.entity.SysUser;
import com.jckj.core.vos.SysUserVo;

import java.lang.reflect.Field;

/**
 * <p>
 *    类值复制工具类
 * </p>
 *
 * @author 刘志远
 * @date 18-1-26
 */
public class ClassUtils {

    /**
     * 两个类对拷
     * @param source
     * @param target
     * @return
     */
    public static void copyValue(Object source, Object target) throws Exception{
        Class sourceClass = source.getClass();
        Class targetClass = target.getClass();
        Field[] fields = sourceClass.getDeclaredFields();
        Field ff = null;
        for(Field f : fields){
            f.setAccessible(true);
            try {
                ff = targetClass.getDeclaredField(f.getName());
            }catch(Exception ex){
                continue;
            }
            if(ff!=null){
                ff.setAccessible(true);
                ff.set(target, f.get(source));
            }
        }
    }

    public static void main(String[] args) throws Exception{
        SysUserVo sysUserVo = new SysUserVo();
        sysUserVo.setPassword("11111");
        SysUser sysUser = new SysUser();
        copyValue(sysUserVo, sysUser);
        System.out.println(sysUser);
    }

}
